<script type="text/javascript">
	var url;
	var LODOP;
	function newDocument(){
		$('#dlg').dialog('open').dialog('setTitle','登记公文记录');
		$('#fm').form('clear');
		url = '<?php echo url('document','add')?>';
	}
	function editDocument(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#dlg').dialog('open').dialog('setTitle','编辑公文记录');
			$('#fm').form('load',row);
			url = '<?php echo url('document','update')?>&id='+row.id;
		}
	}
	function saveDocument(){
		$('#fm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				var result = eval('('+result+')');
				if (result.success){
					$('#dlg').dialog('close');		// close the dialog
					$('#dg').datagrid('reload');	// reload the user data
				} else {
					$.messager.show({
						title: '错误',
						msg: result.msg
					});
				}
			}
		});
	}
	function removeDocument(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('确认','一定要撤销该公文记录吗?',function(r){
				if (r){
					$.post('<?php echo url('document','del')?>',{id:row.id},function(result){
						if (result.success){
							$('#dg').datagrid('reload');	// reload the user data
						} else {
							$.messager.show({	// show error message
								title: '错误',
								msg: result.msg
							});
						}
					},'json');
				}
			});
		}
	}
	function printDocument(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			myPreview(row);
		}
	}
	$(function(){
		$('#dg').datagrid({
			view: detailview,
			detailFormatter:function(index,row){
				return '<div class="ddv"><table>' +
				'<tr><td style="border:0; padding:2px 8px;">来文内容: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.content + '</td></tr>' +
				'<tr><td style="border:0; padding:2px 8px;">拟办意见: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.basic_opinion + '</td></tr>' +
				'<tr><td style="border:0; padding:2px 8px;">领导意见: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.leader_opinion + '</td></tr>' +
				'</table></div>';
			},
		});
	});
	
	function myPreview(row) {		
		CreatePrintPage(row);
		//LODOP.PRINT_DESIGN();
		LODOP.PREVIEW();
	};
	function CreatePrintPage(row) {
		d_arr=row.date.split("-");
		if(row.amount_real==0)row.amount_real='';
		LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));  
		LODOP.PRINT_INIT("文件处理单");
		LODOP.SET_PRINT_PAGESIZE(1,2100,1200,"CreateCustomPage");
		LODOP.SET_PRINT_STYLE("FontColor","#000000");
		LODOP.SET_PRINT_STYLE("FontName","微软雅黑");
		LODOP.SET_PRINT_STYLE("FontSize",12);
		LODOP.SET_PRINT_STYLE("Alignment",2);
		
		LODOP.ADD_PRINT_TEXT(25,20,754,35,"文件处理单");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",18);
		
		LODOP.ADD_PRINT_TEXT(65,20,80,25,"收文日期：");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(65,100,50,25,d_arr[0]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(65,150,25,25,"年");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(65,175,25,25,d_arr[1]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(65,200,25,25,"月");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(65,225,25,25,d_arr[2]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(65,250,25,25,"日");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		
		LODOP.ADD_PRINT_TEXT(65,575,80,25,"收文编号：");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(65,654,120,25,row.num);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_BARCODE(405,20,50,50,"QRCode",row.num);
		LODOP.SET_PRINT_STYLEA(0,"Color","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",1);
		LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);
		
		LODOP.ADD_PRINT_RECT(95,20,754,300,0,1);
		LODOP.ADD_PRINT_RECT(145,20,754,1,0,1);
		LODOP.ADD_PRINT_RECT(195,20,754,1,0,1);
		LODOP.ADD_PRINT_RECT(245,20,754,1,0,1);
		LODOP.ADD_PRINT_RECT(295,20,754,1,0,1);
		LODOP.ADD_PRINT_RECT(345,20,754,1,0,1);
		LODOP.ADD_PRINT_RECT(95,120,1,300,0,1);
		
		LODOP.ADD_PRINT_TEXT(110,20,100,30,"文件标题");
		LODOP.ADD_PRINT_TEXT(160,20,100,30,"来文字号");
		LODOP.ADD_PRINT_TEXT(210,20,100,30,"来文机关");
		LODOP.ADD_PRINT_TEXT(260,20,100,30,"拟办意见");
		LODOP.ADD_PRINT_TEXT(310,20,100,30,"领导意见");
		LODOP.ADD_PRINT_TEXT(360,20,100,30,"传阅人");
		LODOP.ADD_PRINT_TEXT(110,124,650,30,row.title);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(160,124,650,30,row.name);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(210,124,650,30,row.office);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(260,124,650,30,row.basic_opinion);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(310,124,650,30,row.leader_opinion);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
	};
</script>

<table id="dg" title="公文登记与打印" class="easyui-datagrid"
		url="<?php echo url('document','list')?>"
		toolbar="#toolbar" pagination="true"
		rownumbers="true" fitColumns="true" fit="true" singleSelect="true">
	<thead>
		<tr>
			<th field="num" width="50">收文号</th>
			<th field="date" width="50">收文日期</th>
			<th field="name" width="50">来文字号</th>
			<th field="office" width="50">来文机关</th>
			<th field="title" width="100">文件标题</th>
		</tr>
	</thead>
</table>
<div id="toolbar">
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newDocument()">登记公文记录</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editDocument()">编辑公文记录</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeDocument()">撤销公文记录</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" onclick="printDocument()">打印公文记录</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:480px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons">
	<div class="ftitle">公文登记信息</div>
	<form id="fm" method="post" novalidate>
		<div class="fitem">
			<label>来文字号:</label>
			<input name="name" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>来文标题:</label>
			<input name="title" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>来文机关:</label>
			<input name="office" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>来文内容:</label>
			<textarea name="content" class="easyui-validatebox"></textarea>
		</div>
		<div class="fitem">
			<label>拟办意见:</label>
			<textarea name="basic_opinion" class="easyui-validatebox"></textarea>
		</div>
		<div class="fitem">
			<label>领导意见:</label>
			<textarea name="leader_opinion" class="easyui-validatebox"></textarea>
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveDocument()">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>